<template lang="pug">
  kalix-dialog.user-add(bizKey="departments" ref="kalixBizDialog" v-bind:submitBefore="submitBefore"
  v-bind:submitAfter="submitAfter" v-bind:formModel.sync="formModel" v-bind:targetURL="targetURL")
    div.el-form(slot="dialogFormSlot" style=" width:60%;margin:auto;")
      input(v-model="formModel.id" type="hidden")
      input(v-model="formModel.postId" type="hidden")
      el-form-item(label="修改院系名称" prop="content" label-width="120px" v-bind:rules="rules.content")
        el-input(v-model="formModel.content" style="width:80%")
</template>

<script type="text/ecmascript-6">
  import {DepartmentsURL} from '../../config.toml'
  import FormModel from './model'

  export default {
    name: 'DepartmentsEdit',
    data() {
      return {
        labelWidth: '150px',
        tempParent: undefined,
        tempChildren: undefined,
        formModel: Object.assign({}, FormModel),
        rules: {
          content: [{required: true, message: '请输入修改的内容', trigger: 'blur'}]
        },
        targetURL: DepartmentsURL
      }
    },
    methods: {
      submitBefore(baseDialog, callBack) {
        if (baseDialog.formModel.parent) {
          this.tempParent = baseDialog.formModel.parent
          baseDialog.formModel.parent = undefined
        }
        if (baseDialog.formModel.children) {
          this.tempChildren = baseDialog.formModel.children
          baseDialog.formModel.children = undefined
        }
        // console.log('baseDialog==============', baseDialog)
        callBack()
      },
      submitAfter(baseDialog, callBack) {
        if (this.tempParent) {
          baseDialog.formModel.parent = this.tempParent
        }
        if (this.tempChildren) {
          baseDialog.formModel.children = this.tempChildren
        }
        // callBack()
      }
    }
  }
</script>

<style scoped lang="stylus" type="text/stylus">
  .el-form
    width 50%
    margin auto
    .radio
      margin-left 150px
      margin-bottom 20px
      .el-radio
        color: #3465cb
        font-weight: bold
        font-size: 14px
</style>
